#include "util.h"

void memory_copy(char *source, char *dest, int nBytes) {
    for (int i = 0; i < nBytes; i++) {
        dest[i] = source[i];
    }
}

void int_to_ascii(int n, char str[]) {
    int i = 0, length = 0, sign = n;

    if (sign < 0)
        n = -n;

    if (sign < 0)
        str[length++] = '-';

    do {
        str[length++] = n % 10 + '0';
    } while ((n = n / 10) > 0);

    str[length++] = '\0';
    reverse(str);
}

void reverse(char str[]) {
    int c;
    for (int i = 0, j = strlen(str) - 1; i < j; i++, j--) {
        c = str[i];
        str[i] = str[j];
        str[j] = c;
    }
}

int strlen(char str[]) {
    int i = 0;
    while (str[i] != '\0')
        i++;
    return i;
}